package com.example.marketing.market;


import com.example.marketing.business.Order;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 营销框架核心类
 */
public class MarketingEngine {
    private final List<MarketingRule> rules = new ArrayList<>();

    /**
     * 添加营销规则
     *
     * @param rule 营销规则
     * @return 框架实例（支持链式调用）
     */
    public MarketingEngine addRule(MarketingRule rule) {
        rules.add(rule);
        return this;
    }

    /**
     * 处理订单并应用匹配的营销规则
     *
     * @param order 订单信息
     * @return 执行结果
     */
    public List<MarketingResult> processOrder(Order order) {
        return rules.stream()
                .filter(rule -> rule.getCondition().test(order))
                .map(rule -> rule.getAction().execute(order))
                .collect(Collectors.toList());
    }
}

